package com.ruoyi.dingtalk.service;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.dingboot.common.event.Callback;
import com.ruoyi.dingtalk.config.AppConfig;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Service
public class DingTalkService {
    @Resource
    private Callback callback;

    @Resource
    private AppConfig appConfig;

    /**
     * 处理审批回调
     */
    public Map<String, String> dingCallback(HttpServletRequest request, JSONObject jsonObject) {
        String msgSignature = request.getParameter("signature");
        String timeStamp = request.getParameter("timestamp");
        String nonce = request.getParameter("nonce");

        return this.callback.callback(appConfig.getToken(), appConfig.getAes_key(), appConfig.getAppKey(), msgSignature, timeStamp, nonce, jsonObject);
    }
}
